<template>
    <transition name="modal-fade">
        <div class="modal-mask">
            <div class="modal-container">
                <div class="modal-header">
                    <slot name="header">
                        <h3>{{ title }}</h3>
                    </slot>
                    <button class="modal-close" @click="close">×</button>
                </div>
                <div class="modal-body">
                    <slot name="body">
                        <input type="text" v-model="fileName" placeholder="请输入要创建的文件名字">
                    </slot>
                </div>
                <div class="modal-footer">
                    <slot name="footer">
                        <button class="modal-confirm" @click="confirm(fileName)">确认</button>
                        <button class="modal-cancel" @click="close">取消</button>
                    </slot>
                </div>
            </div>
        </div>
    </transition>
</template>

<script setup>
import { ref } from 'vue'


const props =defineProps({
    title: {
        type: String,
        default: '提示'
    },
    fileName: {
        type: String,
    },
    confirm: {
        type: Function
    },
    close: {
        type: Function
    }
})

const fileName = ref(props.fileName)

</script>

<style scoped>
.modal-mask {
    position: fixed;
    z-index: 9998;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

.modal-container {
    width: 500px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
    transition: all 0.3s ease;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    color: #999;
}

.modal-body {
    padding: 20px;
    color: #666;
}

.modal-body>input {
    height: 100%;
    width: 70%;
    padding: 12px 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    outline: none;
}

.modal-body>input:focus {
    border-color: #4285f4;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}


.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    text-align: right;
}

.modal-confirm,
.modal-cancel {
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
}

.modal-confirm {
    background: #409eff;
    color: #fff;
    border: none;
    margin-left: 10px;
}

.modal-cancel {
    background: #fff;
    border: 1px solid #dcdfe6;
    color: #606266;
}

.modal-fade-enter-active,
.modal-fade-leave-active {
    transition: opacity 0.3s;
}

.modal-fade-enter,
.modal-fade-leave-to {
    opacity: 0;
}
</style>
